package Parse;

class ErrorAna{

   private static final String errorline[] = {
    "Error: Unclosed string.",
    "Error: Illegal Token.",
    "Error: Illegal character."
    };
  public static final int E_UNCLOSEDSTR = 0; 
  public static final int E_IllegalToken = 1;
  public static final int E_IllegalChar = 2;
  
}

%%

%implements Lexer
function nextToken
%type java_cup.runtime.Symbol
%char

%{
String string = new String();
private boolean isStr = false;

private void err(String s)
{errorMsg.error(0,s);}


private java_cup.runtime.Symbol tok(int kind,Object value){
	return new java_cup.runtime.Symbol(kind, yychar, yychar + yylength(), value);
	}
	
private ErrorMsg.ErrorMsg errorMsg;
	
Yylex(java.io.InputStream s, ErrorMsg.ErrorMsg e){
	this(s);
	errorMsg = e;
}

%}

%eofval{
	{if (isStr==true) err("String Error!");
	return tok(sym.EOF,null);
	}
%eofval}

Whitespace = \n|\r|\r\n|\t|\r\n
Identifier = [a-z]+([a-z0-9]|_)*
Integer = [0-9]+
Float = [0-9]+[.][0-9]+
StringChar = ["~!@#$%^&*()_-+=[]{}|';:/?.>,<"]
StringTEXT = ([a-z]|[0-9]|{StringChar})*

%state STRING

%%

<YYINITIAL> {Whitespace} {}
<YYINITIAL> ";" {return tok(sym.SEMICOMMA,null);}
<YYINITIAL> "," {return tok(sym.COMMA,null);}
<YYINITIAL> ">" {return tok(sym.GT,null);}
<YYINITIAL> "<" {return tok(sym.LT,null);}
<YYINITIAL> ">=" {return tok(sym.GE,null);}
<YYINITIAL> "<=" {return tok(sym.LE,null);}
<YYINITIAL> "<>" {return tok(sym.NEQ,null);}
<YYINITIAL> "+" {return tok(sym.PLUS,null);}
<YYINITIAL> "-" {return tok(sym.MINUS,null);}
<YYINITIAL> "*" {return tok(sym.TIMES,null);}
<YYINITIAL> "/" {return tok(sym.DIVIDE,null);} 
<YYINITIAL> "%" {return tok(sym.MODE,null);}
<YYINITIAL> "(" {return tok(sym.LPAREN,null);}
<YYINITIAL> ")" {return tok(sym.RPAREN,null);}
<YYINITIAL> "{"  {return tok(sym.LBRACE,null);}
<YYINITIAL> "}" {return tok(sym.RBRACE,null);}

<YYINITIAL> "create" {return tok(sym.CREATE,null);}
<YYINITIAL> "drop" {return tok(sym.DROP,null);}
<YYINITIAL> "select" {return tok(sym.SELECT,null);}
<YYINITIAL> "insert" {return tok(sym.INSERT,null);}
<YYINITIAL> "update" {return tok(sym.UPDATE,null);}
<YYINITIAL> "delete" {return tok(sym.DELETE,null);}
<YYINITIAL> "start" {return tok(sym.START,null);}
<YYINITIAL> "set" {return tok(sym.SET,null);}
<YYINITIAL> "end" {return tok(sym.END,null);}
<YYINITIAL> "order" {return tok(sym.ORDER,null);}

<YYINITIAL> "database" {return tok(sym.DATABASE,null);}
<YYINITIAL> "table" {return tok(sym.TABLE,null);}
<YYINITIAL> "view" {return tok(sym.VIEW,null);}
<YYINITIAL> "transaction" {return tok(sym.TRANSACTION,null);}
<YYINITIAL> "index" {return tok(sym.INDEX,null);}

<YYINITIAL> "primary" {return tok(sym.PRIMARY,null);}
<YYINITIAL> "foreign" {return tok(sym.FOREIGN,null);}
<YYINITIAL> "KEY" {return tok(sym.KEY,null);}
<YYINITIAL> "references" {return tok(sym.REFERENCES,null);}
<YYINITIAL> "check" {return tok(sym.CHECK,null);}
<YYINITIAL> "unique" {return tok(sym.UNIQUE,null);}
<YYINITIAL> "group" {return tok(sym.GROUP,null);}
<YYINITIAL> "having" {return tok(sym.HAVING,null);}
<YYINITIAL> "default" {return tok(sym.DEFAULT,null);}
<YYINITIAL> "distinct" {return tok(sym.DISTINCT,null);}
<YYINITIAL> "ASC" {return tok(sym.ASC,null);}
<YYINITIAL> "DESC" {return tok(sym.DESC,null);}

<YYINITIAL> "null" {return tok(sym.NULL,null);}
<YYINITIAL> "not" {return tok(sym.NOT,null);}

<YYINITIAL> "int" {return tok(sym.INT,null);}
<YYINITIAL> "float" {return tok(sym.FLOAT,null);}
<YYINITIAL> "char" {return tok(sym.CHAR,null);}
<YYINITIAL> "boolean" {return tok(sym.BOOLEAN,null);}
<YYINITIAL> "varchar" {return tok(sym.VARCHAR,null);}
<YYINITIAL> "datetime" {return tok(sym.DATETIME,null);}
<YYINITIAL> "blob" {return tok(sym.BLOB,null);}

<YYINITIAL> "into" {return tok(sym.INTO,null);}
<YYINITIAL> "value" {return tok(sym.VALUE,null);}
<YYINITIAL> "where" {return tok(sym.WHERE,null);}
<YYINITIAL> "from" {return tok(sym.FROM,null);}
<YYINITIAL> "by" {return tok(sym.BY,null);}
<YYINITIAL> "as" {return tok(sym.AS,null);}
<YYINITIAL> "any" {return tok(sym.ANY,null);}
<YYINITIAL> "in" {return tok(sym.IN,null);}
<YYINITIAL> "all" {return tok(sym.ALL,null);}
<YYINITIAL> "on" {return tok(sym.ON,null);}

<YYINITIAL> "read only" {return tok(sym.READONLY,null);}
<YYINITIAL> "read write" {return tok(sym.READWRITE,null);}
<YYINITIAL> "read uncommitted" {return tok(sym.UNCOMMITTED,null);}
<YYINITIAL> "read committed" {return tok(sym.COMMITTED,null);}
<YYINITIAL> "repeatable read" {return tok(sym.REPEATREAD,null);}
<YYINITIAL> "serializable" {return tok(sym.SERIAL,null);}

<YYINITIAL> {Identifier} {return tok(sym.ID,yytext());}
<YYINITIAL> {Integer} {return tok(sym.INT,new Integer(yytext()));}
<YYINITIAL> {Float} {return tok(sym.FLOAT,new Float(yytext()));} 

<YYINITIAL> \' { yybegin(STRING);string="";isStr=true;}
<STRING> {StringTEXT} {string = string + yytext();}
<STRING> \' {yybeign(YYINITIAL);isStr=false;return tok(sym.STR,string.tostring());}

